import type { ConsultType } from '@/enums'
import type { ConsultIllness } from '@/types/consult'
import type { PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useConsultStore = defineStore(
  'count',
  () => {
    // 问诊仓库
    const consult = ref<PartialConsult>({})
    // 记录问诊类型
    const setType = (type: ConsultType) => (consult.value.type = type)
    // 选择问诊级别
    const setIllnessType = (type: 0 | 1) => (consult.value.illnessType = type)
    // 选择问诊科室
    const setDep = (depId: string) => (consult.value.depId = depId)
    // 记录问诊描述
    const setIllness = (illness: ConsultIllness) => {
      // 问诊文字描述
      consult.value.illnessDesc = illness.illnessDesc
      // 问诊的患病时间
      consult.value.illnessTime = illness.illnessTime
      // 是否就诊
      consult.value.consultFlag = illness.consultFlag
      // 补充的图片
      consult.value.pictures = illness.pictures
    }
    // 记录患者id
    const setPatient = (id: string) => (consult.value.patientId = id)
    // 记录优惠券id
    const setCoupon = (id: string) => (consult.value.couponId = id)
    // 清理订单数据
    const clear = () => (consult.value = {})
    return {
      setType,
      setIllnessType,
      setDep,
      setIllness,
      setPatient,
      setCoupon,
      clear,
      consult
    }
  },
  {
    persist: true // 持久化
  }
)
